package com.scgl.zuzhi.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.scgl.zuzhi.domain.ScglDepartment;
import com.scgl.zuzhi.service.IScglDepartmentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 部门Controller
 *
 * @author ruoyi
 * @date 2024-10-25
 */
@RestController
@RequestMapping("/department")
public class ScglDepartmentController extends BaseController
{
    @Autowired
    private IScglDepartmentService scglDepartmentService;

    /**
     * 查询部门列表
     */
    @RequiresPermissions("zuzhi:department:list")
    @GetMapping("/list")
    public AjaxResult list(ScglDepartment scglDepartment)
    {
        List<ScglDepartment> list = scglDepartmentService.selectScglDepartmentList(scglDepartment);
        return AjaxResult.success(list);
    }

    /**
     * 导出部门列表
     */
    @RequiresPermissions("zuzhi:department:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScglDepartment scglDepartment)
    {
        List<ScglDepartment> list = scglDepartmentService.selectScglDepartmentList(scglDepartment);
        ExcelUtil<ScglDepartment> util = new ExcelUtil<ScglDepartment>(ScglDepartment.class);
        util.exportExcel(response, list, "部门数据");
    }

    /**
     * 获取部门详细信息
     */
    @RequiresPermissions("zuzhi:department:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scglDepartmentService.selectScglDepartmentById(id));
    }

    /**
     * 新增部门
     */
    @RequiresPermissions("zuzhi:department:add")
    @PostMapping
    public AjaxResult add(@RequestBody ScglDepartment scglDepartment)
    {
        return toAjax(scglDepartmentService.insertScglDepartment(scglDepartment));
    }

    /**
     * 修改部门
     */
    @RequiresPermissions("zuzhi:department:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody ScglDepartment scglDepartment)
    {
        return toAjax(scglDepartmentService.updateScglDepartment(scglDepartment));
    }

    /**
     * 删除部门
     */
    @RequiresPermissions("zuzhi:department:remove")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scglDepartmentService.deleteScglDepartmentByIds(ids));
    }
}
